import {Component, ViewEncapsulation} from '@angular/core';
import {BaThemeSpinner}  from '../../../theme/services';
import {IdeaService} from '../../../services/app.idea';
import './pieChart.loader';

@Component({
    selector: 'pie-chart',
    encapsulation: ViewEncapsulation.None,
    styleUrls: ['./pieChart.scss'],
    templateUrl: './pieChart.html'
})

export class PieChart {

    public totalIdeaCount:any;
    public totalCommentCount:any;
    public userIdeaCount:any;
    public userCommentCount:any;

    constructor(private ideaService:IdeaService, private spinner:BaThemeSpinner) {
        // call dashboard stats
        this.getDashBoardStas();
    }

    // Function for call API of dashboard stats
    private getDashBoardStas() {
        this.spinner.showProgress();
        let input = {};
        this.ideaService.setDashBoardData(input).subscribe(
            data => this.dashBoardSucess(data),
            error => this.dashBoardFailure(error)
        );
    }

    // Function call if dashboard stats success
    private dashBoardSucess(stats) {
        this.totalIdeaCount = stats.totalIdeaCount;
        this.totalCommentCount = stats.totalCommentCount;
        this.userIdeaCount = stats.userIdeaCount;
        this.userCommentCount = stats.userCommentCount;
    }

    // Function call if dashboard stats failed
    private dashBoardFailure(error) {
        this.spinner.hideProgress();
    }
}
